//
//  UIButton+Extension.swift
//  swiftweibo
//
//  Created by 吕建发 on 16/5/15.
//  Copyright © 2016年 cn.itcast. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(gk_title title: String,
                              font: CGFloat = 16,
                              imageName: String? = nil,
                              backImageName: String? = nil,
                              titleColor: UIColor) {
        
        self.init()
        self.setTitle(title, forState: .Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(font)
        self.setTitleColor(titleColor, forState: .Normal)
        self.setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        
        // 判断传入的imageName是否有值来设置image
        if let imageName = imageName {
            self.setImage(UIImage(named: imageName), forState: .Normal)
            self.setImage(UIImage(named: imageName + "highlighted"), forState: .Highlighted)
        }
        
        if let backImageName = backImageName {
            self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            self.setBackgroundImage(UIImage(named: backImageName + "highlighted"), forState: .Highlighted)
        }
        
        self.sizeToFit()
    }
    
    
}


